package middlewareLogExtraction.model;

import java.util.regex.Matcher;

public class RecordTimeStrParser {
	private int minutes;
	private int seconds;
	private int miliseconds;

	private final String timePattern = "(\\d+m)?(\\d+).(\\d{3})s";

	public RecordTimeStrParser parseTimeStr(String timeStr,
			RegexHelper regexHelper) {
		Matcher matcher = regexHelper.regexFind(timeStr, timePattern);
		if (matcher != null) {
			int groupCount = matcher.groupCount();
			if (matcher.group(1) != null)
				this.minutes = new Integer(matcher.group(1).replace("m", ""))
						.intValue();
			this.seconds = new Integer(matcher.group(2)).intValue();
			this.miliseconds = new Integer(matcher.group(3)).intValue();
		}
		return this;
	}

	public int getMinutes() {
		return minutes;
	}

	public int getSeconds() {
		return seconds;
	}

	public int getMiliseconds() {
		return miliseconds;
	}

	public int toSeconds() {
		return this.minutes * 60 + this.seconds;
	}

}
